<template>
  <div style="width: 100%;height: 100vh;background-color: deepskyblue;overflow: hidden">
    <div style="width: 400px;margin: 150px auto;">
      <div style="color: aliceblue;font-size: 30px;text-align: center;padding: 30px 0">欢迎注册</div>

      <el-form ref="formRef" :rules="rules" :model="form" size="large" >
        <el-form-item prop="username">
          <el-input v-model="form.username">
            <template #prefix>
              <el-icon size="150" style="top:15px">
                <UserFilled/>
              </el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" show-password>
            <template #prefix>
              <el-icon size="50" style="top:15px">
                <Lock/>
              </el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="confirm">
          <el-input v-model="form.confirm" show-password>
            <template #prefix>
              <el-icon size="50" style="top:15px">
                <Lock/>
              </el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%;font-size: 25px" @click="register">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {User, UserFilled, Search, Lock} from '@element-plus/icons-vue'
import request from "@/utils/request";

export default {
  name: "Regist",
  data() {
    return {
      form: {},
      rules: {
        username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
        password: [{required: true, message: '请输入密码', trigger: 'blur'}],
        confirm: [{required: true, message: '确认密码', trigger: 'blur'}]
      }
    }
  },
  components: {
    User, UserFilled, Search, Lock
  },
  methods: {
    register() {
      if (this.form.password !== this.form.confirm) {
        this.$message({
          type: "error",
          message: "2次密码不一致"
        })
        return
      }
      request.post("/user/register", this.form).then(res => {
        if (res.resultCode === 0) {
          this.$message({
            type: "success",
            message: "注册成功"
          })
          this.$router.push("/login") //登录成功页面跳转
        } else {
          this.$message({
            type: "error",
            message: "失败"
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
